<template>
  <base-modal :title="editVacationTitle" :show.sync="vacationVisible" width="420px" @closed="resetEditVacation">
    <div class="edit-vacation-modal">
      <el-form label-position="top" ref="editVacationForm" :model="editVacationForm" :rules="editVacationRules">
        <el-form-item :label="$t('common.base.date')" prop="dateTime" >
          <el-date-picker
            class="vacation-date-picker"
            v-model="editVacationForm.dateTime"
            type="daterange"
            :range-separator="$t('common.base.to')"
            :start-placeholder="$t('common.base.startDate')"
            :end-placeholder="$t('common.base.endDate')"
            value-format="timestamp"
            :default-time="['00:00:00', '23:59:59']"
            :clearable="false"
            align="right">
          </el-date-picker>
        </el-form-item>
        <el-form-item :label="$t('common.base.remark')" prop="remarks">
          <el-input type="textarea" v-model="editVacationForm.remarks" :rows="4"></el-input>
        </el-form-item>
      </el-form>
    </div>
    
    <div slot="footer" class="dialog-footer">
      <el-button type="plain-third" @click="vacationVisible = false" >{{ $t('common.base.cancel') }}</el-button>
      <el-button type="primary" @click="editVacation()" :disabled="pending">{{ $t('common.base.makeSure') }}</el-button>
    </div>
  </base-modal>
</template>
<script>
export default {
  name: 'edit-vacation-dialog',
  props: {
    editVacationTitle: {
      type: String,
      default: ''
    },
    editVacationForm: {
      type: Object,
      default: () => ({})
    },
    editVacationRules: {
      type: Object,
      default: () => ({})
    },
    pending: {
      type: Boolean,
      default: false
    },
  },
  data() {
    return {
      vacationVisible: false
    }
  },
  methods: {
    open() {
      this.vacationVisible = true
    },
    close() {
      this.vacationVisible = false
    },
    resetEditVacation() {
      this.$emit('rest')
    },
    editVacation() {
      this.$refs.editVacationForm.validate(valid => {
        if(valid) {
          this.$emit('edit')
        }
      })
      
    }
  }
}
</script>
<style scoped lang="scss">
.edit-vacation-modal {
  padding: 10px;
}
</style>